using HKB.Common;
using HKB.Data.Dal;
using HKB.Data.Model;
using System;
using System.Collections.Generic;
using System.Data;
namespace HKB.Data.Bll
{
	public class ShopAdBll
	{
		private static ShopAdBll _instance = null;
		private readonly ShopAdDal dal = new ShopAdDal();
		public static ShopAdBll instance
		{
			get
			{
				if (ShopAdBll._instance == null)
				{
					ShopAdBll._instance = new ShopAdBll();
				}
				return ShopAdBll._instance;
			}
		}
		public bool Exists(string AdName)
		{
			return this.dal.Exists(AdName);
		}
		public void Add(ShopAdModel model)
		{
			this.dal.Add(model);
		}
		public bool Update(ShopAdModel model)
		{
			return this.dal.Update(model);
		}
		public bool Delete(string AdName)
		{
			return this.dal.Delete(AdName);
		}
		public ShopAdModel GetModel(string AdName)
		{
			return this.dal.GetModel(AdName);
		}
		public ShopAdModel GetModelByCache(string AdName)
		{
			string cacheKey = "ShopAdModel_" + AdName;
			object obj = DataCache.GetCache(cacheKey);
			if (obj == null)
			{
				try
				{
					obj = this.dal.GetModel(AdName);
					if (obj != null)
					{
						int configInt = ConfigHelper.GetConfigInt("ModelCache");
						DataCache.SetCache(cacheKey, obj, System.DateTime.Now.AddMinutes((double)configInt), System.TimeSpan.Zero);
					}
				}
				catch
				{
				}
			}
			return (ShopAdModel)obj;
		}
		public DataSet GetList(string strWhere)
		{
			return this.dal.GetList(strWhere);
		}
		public DataSet GetList(int Top, string strWhere, string filedOrder)
		{
			return this.dal.GetList(Top, strWhere, filedOrder);
		}
		public System.Collections.Generic.List<ShopAdModel> GetModelList(string strWhere)
		{
			DataSet list = this.dal.GetList(strWhere);
			return this.DataTableToList(list.Tables[0]);
		}
		public System.Collections.Generic.List<ShopAdModel> DataTableToList(DataTable dt)
		{
			System.Collections.Generic.List<ShopAdModel> list = new System.Collections.Generic.List<ShopAdModel>();
			int count = dt.Rows.Count;
			if (count > 0)
			{
				for (int i = 0; i < count; i++)
				{
					list.Add(new ShopAdModel
					{
						AdType = dt.Rows[i]["AdType"].ToString(),
						AdName = dt.Rows[i]["AdName"].ToString(),
						AdUrl = dt.Rows[i]["AdUrl"].ToString(),
						AdSrc = dt.Rows[i]["AdSrc"].ToString(),
						AdTitle = dt.Rows[i]["AdTitle"].ToString()
					});
				}
			}
			return list;
		}
		public DataSet GetAllList()
		{
			return this.GetList("");
		}
		public DataSet GetListRowid(int Top, string strWhere, string filedOrder, params string[] selectField)
		{
			return this.dal.GetListRowid(Top, strWhere, filedOrder, selectField);
		}
		public DataSet PageOrderList(int PageSize, int PageIndex, string Orderfld, int OrderType, string strWhere)
		{
			int num = (PageIndex - 1) * PageSize;
			return Conn.ExecProSpPageOrder("HL_ShopAd", " " + num + "+ (ROW_NUMBER() OVER (ORDER BY AdName ASC)) rowid,*", PageSize, PageIndex, Orderfld, OrderType, strWhere);
		}
	}
}
